package com.polaris.live.adapter.level

import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.common.R.color
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterRichCharmLevelBinding
import com.polaris.live.resp.bean.LevelUpRewardBean

/**
 * MeCharmRichLevelAdapter
 *
 * @author Created by 半仙 on 2024/2/1/001 17:46
 */
class MeCharmRichLevelAdapter(
    private val mType: Int,
) : BaseBindingAdapter<AdapterRichCharmLevelBinding, LevelUpRewardBean>() {

    private var mSelectPosition = 0
    override fun convert(holder: VBViewHolder<AdapterRichCharmLevelBinding>, item: LevelUpRewardBean) {
        holder.vb.apply {
            val position = holder.absoluteAdapterPosition
            if (position == 0) {
                leftview.visibility = View.VISIBLE
            } else {
                leftview.visibility = View.GONE
            }
            setColor(holder)
            if (position == mSelectPosition) {
                tvLevel.setTextColor(ColorUtils.getColor(color.white))
                if (mType == RICH) {
                    cosBack.setBackgroundColor(ColorUtils.getColor(color.color_ffaa01))
                } else {
                    cosBack.setBackgroundColor(ColorUtils.getColor(color.color_ff93f1))
                }
            } else {
                tvLevel.setTextColor(ColorUtils.getColor(color.color_202028))
                if (mType == RICH) {
                    cosBack.setBackgroundColor(ColorUtils.getColor(R.color.color_fff9ef))
                } else {
                    cosBack.setBackgroundColor(ColorUtils.getColor(R.color.color_fff4fd))
                }
            }
            tvLevel.text = "L${item.level}"
        }
    }

    private fun setColor(holder: VBViewHolder<AdapterRichCharmLevelBinding>) {
        holder.vb.apply {
            if (mType == RICH) {
                leftview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ffaa01))
                topview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ffaa01))
                rightview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ffaa01))
                bottomview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ffaa01))
            } else {
                leftview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ff93f1))
                topview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ff93f1))
                rightview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ff93f1))
                bottomview.setBackgroundColor(ColorUtils.getColor(R.color.color_40ff93f1))
            }
        }
    }

    fun setSelect(position: Int) {
        mSelectPosition = position
        notifyDataSetChanged()
    }

    companion object {
        const val RICH = 1              //豪气值
        const val CHARM = 2             //魅力值
    }
}